package com.github.easyms.web.controller;

import com.github.easyms.common.util.RequestHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 语言包
 *
 * @author Leo.Liao
 * @date 2020-05-18 10:38:52
 */
@Controller
@RequestMapping("/index")
public class LangPackController {

    /**
     * 默认语言
     */
    @Value("${properties.defaultLang}")
    private String defaultLang;

    /**
     * 获取功能界面语言包
     * @param module
     * @param func
     * @param request
     * @return
     */
    @GetMapping("/languagePack/{module}/{func}")
    public String languagePack(@PathVariable String module, @PathVariable String func, HttpServletRequest request) {
        String language = RequestHelper.getLanguage(request,defaultLang).toString();
        String langPackPath = "/h5/lang/lang-" + language + "/";
        langPackPath += module + "/";
        String langPackFileName = "lang-" + language + "-" + func + ".js";
        return "redirect:" + langPackPath + langPackFileName;
    }

    /**
     * 获取EasyUI语言包
     * @param request
     * @return
     */
    @GetMapping("/easyuiLanguagePack")
    public String easyuiLanguagePack(HttpServletRequest request) {
        String language = RequestHelper.getLanguage(request,defaultLang).toString();
        String langPackFileName = "/h5/plugin/jquery-easyui-1.9.4/locale/easyui-lang-" + language + ".js";
        return "redirect:" + langPackFileName;
    }

}
